import os
import secrets
from conf import conf

def work(n=128, bits=128):
    filename = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/') + "/../../"
    filename += "data/server/key.txt"
    byte_length = bits // 8  # 128 bits = 16 bytes
    with open(filename, 'w') as f:
        for i in range(n):
            string = secrets.token_hex(byte_length)
            f.write(string + '\n')
    ks = secrets.token_hex(byte_length)
    conf.set_config('select_key', ks)
    f.close()

if __name__ == '__main__':
    work()